package com.example.app.pages.main.home.addNew.addRecord

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import com.example.app.addNewViewModel
import com.example.app.components.MyEmptyShow.MyEmptyTextShow
import com.example.app.components.MyIcon.MyDoneIcon
import com.example.app.components.MyListItem.MyListItem
import com.example.app.components.MyText.MyText
import com.example.app.pages.main.home.addNew.addRecord.MyModalBottomSheetRelationPicker.myModalBottomSheetRelationPickerState
import com.example.app.pages.main.home.me.viewModel.AddNewViewModel

@Composable
fun IncomeAccountRelationPeopleList(

) {
    var accountRelationPeopleList = addNewViewModel.accountRelationPeopleList.collectAsState()
    var selected = myModalBottomSheetRelationPickerState.selected.collectAsState()



    Column(
        Modifier
            .verticalScroll(rememberScrollState())
    ) {
        if (accountRelationPeopleList.value != null && accountRelationPeopleList.value!!.size > 0) {
            accountRelationPeopleList.value?.forEach { accountRelationPeople ->
                MyListItem(headlineContent = {
                    MyText(text = accountRelationPeople.Title.toString())
                },
                    trailingContent = {
                        if (selected != null && selected.value?._id == accountRelationPeople._id) {
                            MyDoneIcon()
                        }
                    },
                    modifier = Modifier.clickable {
                        myModalBottomSheetRelationPickerState.flowUpdate_selected(accountRelationPeople)
                    })
            }
        } else {
            MyEmptyTextShow()
        }
    }
}